<template>
	<view class="">
		<uni-popup ref="popup" type="bottom" background-color="#fff" borderRadius="20rpx 20rpx 0 0" @change="change">
			<view class="popup-wrap">
				<view class="popup-header">
					<view class="popup-header-title">
						<text>请选择服务规格</text>
					</view>
					<view class="popup-header-close" @click="close">
						<image :src="$img_path('/home/icon-close.png')" mode="widthFix"></image>
					</view>
				</view>
				<view class="popup-content">
					<view class="popup-content-title">
						<text>规格名称</text>
					</view>
					<view class="popup-content-list">
						<scroll-view scroll-y="true" style="height: 100%;">
							<view class="popup-content-list-item" v-for="(item, index) in skus" :key="index" @click="selectSkuItem(item)">
								<goodsSkuItemVue v-if="type == 'select'" :sku="item" :is-active="item.id == skuItem.id" />
								<goodsSkuItemNumVue v-else :sku="item" :is-active="item.id == skuItem.id" />
							</view>
						</scroll-view>
					</view>
				</view>
				<view class="popup-bottom-btn common-btn-bg-color" @click="confirm">
					<text>确定</text><br/>
					<text class="total" v-if="isTotal">（合计¥300）</text>
				</view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	import goodsSkuItemVue from '../goods-sku-item/goods-sku-item.vue'
	import goodsSkuItemNumVue from '../goods-sku-item/goods-sku-item-num.vue'
	export default {
		components: {
			goodsSkuItemVue,
			goodsSkuItemNumVue
		},
		props: {
			skus: {
				type: Array,
				default: []
			},
			type: {
				type: String,
				default: "select"
			},
			isTotal: {
				type: Boolean,
				default: false
			}
		},
		data() {
			return {
				skuItem: {}
			}
		},
		watch: {
			skus(val) {
				if(val.length > 0) {
					console.log("Skus changed to", val);
					this.skuItem = val[0]
					console.log("Set skuItem to", this.skuItem);
				} else {
					console.log("Skus is empty");
				}
			}	
		},
		methods: {
			change(e) {
				console.log("e", e);	
				if(!e.show) {
					this.$emit("close")
				}
			},
			open() {
				this.$refs.popup.open()
			},
			
			close() {
				this.$refs.popup.close()
			},
			
			selectSkuItem(item) {
				this.skuItem = item
			},
			
			confirm() {
				this.$emit("confirm", this.skuItem)
				this.close()
			}
		}
	}
</script>

<style scoped lang="scss">
	.popup-wrap {
		padding: 36rpx 22rpx 68rpx 22rpx;
		box-sizing: border-box;
		// height: 946rpx;
		// position: relative;
		display: flex;
		flex-direction: column;
		
		image {
			width: 100%;
			height: 100%;
		}
	}
	
	.popup-header {
		display: flex;
		align-items: center;
	}
	
	.popup-header-title {
		flex: 1;
		text-align: center;
		font-weight: bold;
		font-size: 36rpx;
		color: #333333;
	}
	
	.popup-header-close {
		// position: absolute;
		width: 32rpx;
		height: 32rpx;
	}
	
	.popup-content {
		margin-top: 46rpx;
		flex: 1;
		display: flex;
		flex-direction: column;
	}
	
	.popup-content-title {
		font-weight: bold;
		font-size: 34rpx;
		color: #333333;
	}
	
	.popup-content-list {
		height: 550rpx;
	}
	
	.popup-content-list-item {
		margin-top: 24rpx;
	}
	
	.popup-bottom-btn {
		font-weight: bold;
		font-size: 36rpx;
		color: #FFFFFF;
		height: 96rpx;
		border-radius: 80rpx;
		width: 100%;
		margin-top: 56rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		flex-direction: column;
		
		.total {
			font-weight: bold;
			font-size: 26rpx;
			color: #FFFFFF;
		}
	}
</style>